package me.yxy.mobanddd.components;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 用来封装{@link org.springframework.data.domain.Page}对象，去掉一些多余的返回
 */
@Getter
public class MPage<T> {

    private Paging paging;

    private List<T> content;

    private MPage(Page<T> page){
        this.content = page.getContent();
        this.paging = new Paging(page.getTotalElements(),page.getTotalPages(),page.isFirst(),page.isLast(),page.getNumber(),page.getSize());
    }

    public static MPage of(Page page){
        return new MPage(page);
    }

    @Data
    @AllArgsConstructor
    public static class Paging{
        private long totalRows;
        private int totalPages;
        private boolean first;
        private boolean last;
        private int pageNumber;
        private int pageSize;
    }


}

